<!-- 角色权限分配弹窗 -->
<template>
  <el-dialog
    title="发放优惠卷"
    :visible="visible"
    width="750px"
    :destroy-on-close="true"
    :lock-scroll="false"
    custom-class="ele-dialog-form"
    @update:visible="updateVisible">
    <el-form
      ref="form"
      label-width="82px">

  <el-form-item
    label="会员手机号:"
    prop="phone">
    <el-input
      type="text"
      :maxlength="20"
      v-model="form.phone"
      placeholder="请输入会员手机号"
      clearable/>
  </el-form-item>

    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button
        type="primary"
        @click="save"
        :loading="loading">保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'CradArea',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 当前角色数据
    data: Object
  },
  data() {
    return {
      subItem: {
        'type': 'checkbox',
        'title': '周期',
        'list': {
          '1': '周一',
          '2': '周二',
          '3': '周三',
          '4': '周四',
          '5': '周五',
          '6': '周六',
          '7': '周日'
        },
      },
      subItem1: {
        'type': 'radio',
        'title': '是否通用',
        'list': {
          1: "开启",
          2: "关闭"
        },
      },
      storeList: {
        'store1': {
          '1': '茶室1',
        },'store2': {
          '1': '茶室2',
        },'store3': {
          '1': '茶室3',
        },'store4': {
          '1': '茶室4',
        },'store5': {
          '1': '茶室5',
        },'store6': {
          '1': '茶室6',
        },'store7': {
          '1': '茶室7',
        },'store8': {
          '1': '茶室8',
        },'store9': {
          '1': '茶室9',
        },'store10': {
          '1': '茶室10',
        },
      },
      store: {
        'store1': false,
        'store2': false,
        'store3': false,
        'store4': false,
        'store5': false,
        'store6': false,
        'store7': false,
        'store8': false,
        'store9': false,
        'store10': false
      },
      form: {
     },
      // 权限数据
      authData: [],
      // 权限数据请求状态
      authLoading: false,
      // 提交状态
      loading: false,
      // 表单数据
      // form: this.data,
      rules: {},
    };
  },
  computed: {
    // 权限树选中数据
    checked() {
      let checked = [];
      this.$util.eachTreeData(this.authData, d => {
        if (d.checked && (!d.children || !d.children.length)) {
          checked.push(d.id);
        }
      });
      return checked;
    }
  },
  watch: {
  data() {
    if (this.data) {
    
      this.form = Object.assign({}, this.data, {
        id: this.data.id,
      });
      this.isUpdate = true;
    } else {
      this.form = {};
      this.isUpdate = false;
    }
  },
    visible() {
      if (this.visible) {

      }
    }
  },
  methods: {
    /* 查询权限数据 */

    /* 保存权限分配 */
    save() {
      this.loading = true;
      this.$http.post('/coupon/saveCradArea', this.form).then(res => {
        this.loading = false;
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.updateVisible(false);
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.loading = false;
        this.$message.error(e.message);
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    },
    keyChange1(value) {
      if (this.form.store1.status[0] != '1' && value.length > 0) this.form.store1.status = ['1'];
    },
    keyChange2(value) {
      if (this.form.store2.status[0] != '1' && value.length > 0) this.form.store2.status = ['1'];
    },
    keyChange3(value) {
      if (this.form.store3.status[0] != '1' && value.length > 0) this.form.store3.status = ['1'];
    },
    keyChange4(value) {
      if (this.form.store4.status[0] != '1' && value.length > 0) this.form.store4.status = ['1'];
    },
    keyChange5(value) {
      if (this.form.store5.status[0] != '1' && value.length > 0) this.form.store5.status = ['1'];
    },
    keyChange6(value) {
      if (this.form.store6.status[0] != '1' && value.length > 0) this.form.store6.status = ['1'];
    },
    keyChange7(value) {
      if (this.form.store7.status[0] != '1' && value.length > 0) this.form.store7.status = ['1'];
    },
    keyChange8(value) {
      if (this.form.store8.status[0] != '1' && value.length > 0) this.form.store8.status = ['1'];
    },
    keyChange9(value) {
      if (this.form.store9.status[0] != '1' && value.length > 0) this.form.store9.status = ['1'];
    },
    keyChange10(value) {
      if (this.form.store10.status[0] != '1' && value.length > 0) this.form.store10.status = ['1'];
    },
    arrChange1(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store1.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store1.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store1.value = array;
          }
          break;
        default:
          if (this.store.store1) {
            this.form.store1.status = [];
            this.form.store1.value = []
          }
          break;
      }
    },
    arrChange2(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store2.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store2.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store2.value = array;
          }
          break;
        default:
          if (this.store.store2) {
            this.form.store2.status = [];
            this.form.store2.value = []
          }
          break;
      }
    },
    arrChange3(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store3.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store3.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store3.value = array;
          }
          break;
        default:
          if (this.store.store3) {
            this.form.store3.status = [];
            this.form.store3.value = []
          }
          break;
      }
    },
    arrChange4(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store4.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store4.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store4.value = array;
          }
          break;
        default:
          if (this.store.store4) {
            this.form.store4.status = [];
            this.form.store4.value = []
          }
          break;
      }
    },
    arrChange5(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store5.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store5.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store5.value = array;
          }
          break;
        default:
          if (this.store.store5) {
            this.form.store5.status = [];
            this.form.store5.value = []
          }
          break;
      }
    },
    arrChange6(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store6.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store6.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store6.value = array;
          }
          break;
        default:
          if (this.store.store6) {
            this.form.store6.status = [];
            this.form.store6.value = []
          }
          break;
      }
    },
    arrChange7(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store7.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store7.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store7.value = array;
          }
          break;
        default:
          if (this.store.store7) {
            this.form.store7.status = [];
            this.form.store7.value = []
          }
          break;
      }
    },
    arrChange8(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store8.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store8.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store8.value = array;
          }
          break;
        default:
          if (this.store.store8) {
            this.form.store8.status = [];
            this.form.store8.value = []
          }
          break;
      }
    },
    arrChange9(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store9.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store9.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store9.value = array;
          }
          break;
        default:
          if (this.store.store9) {
            this.form.store9.status = [];
            this.form.store9.value = []
          }
          break;
      }
    },
    arrChange10(value) {
      var arr = {}, length = 0, array = [];
      switch (value[0]) {
        case '1':
          arr = Object.keys(this.form.store10.list),
            length = arr.length,
            array = [];
          if (length > 0) {
            this.form.store10.status = ['1'];
            for (var i=1;i<=length;i++) {
              array.push(i + "");
            }
            this.form.store10.value = array;
          }
          break;
        default:
          if (this.store.store10) {
            this.form.store10.status = [];
            this.form.store10.value = []
          }
          break;
      }
    },
    agreeChange(value) {
      if (value == 1) {
        var arr = Object.keys(this.form.store1.list);
        var length = arr.length,
          array = [],
          i = 1;
        if (length > 0) {
          this.form.store1.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store1.value = array;
        }
        arr = Object.keys(this.form.store2.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store2.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store2.value = array;
        }
        arr = Object.keys(this.form.store3.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store3.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store3.value = array;
        }
        arr = Object.keys(this.form.store4.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store4.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store4.value = array;
        }
        arr = Object.keys(this.form.store5.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store5.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store5.value = array;
        }
        arr = Object.keys(this.form.store6.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store6.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store6.value = array;
        }
        arr = Object.keys(this.form.store7.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store7.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store7.value = array;
        }
        arr = Object.keys(this.form.store8.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store8.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store8.value = array;
        }
        arr = Object.keys(this.form.store9.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store9.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store9.value = array;
        }
        arr = Object.keys(this.form.store10.list);
        length = arr.length;
        array = [];
        if (length > 0) {
          this.form.store10.status = ['1'];
          for (i=1;i<=length;i++) {
            array.push(i + "");
          }
          this.form.store10.value = array;
        }
      } else {
        if (this.store.store1) {
          this.form.store1.status = [];
          this.form.store1.value = []
        }
        if (this.store.store2) {
          this.form.store2.status = [];
          this.form.store2.value = []
        }
        if (this.store.store3) {
          this.form.store3.status = [];
          this.form.store3.value = []
        }
        if (this.store.store4) {
          this.form.store4.status = [];
          this.form.store4.value = []
        }
        if (this.store.store5) {
          this.form.store5.status = [];
          this.form.store5.value = []
        }
        if (this.store.store6) {
          this.form.store6.status = [];
          this.form.store6.value = []
        }
        if (this.store.store7) {
          this.form.store7.status = [];
          this.form.store7.value = []
        }
        if (this.store.store8) {
          this.form.store8.status = [];
          this.form.store8.value = []
        }
        if (this.store.store9) {
          this.form.store9.status = [];
          this.form.store9.value = []
        }
        if (this.store.store10) {
          this.form.store10.status = [];
          this.form.store10.value = []
        }
      }
    }
  }
}
</script>

<style scoped>
</style>
